﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using V = Science.Mathematics.VectorCalculus;

namespace VectorCalculus5Ed.Chapter2.Section1
{
    public class Example03
    {
        public Example03()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
        public void Compute()
        {
            V.Function.ToLastType<double, double, double[]> cf
                = new V.Function.ToLastType<double, double, double[]>(Box);
            V.Domain2D xd = new V.Domain2D();
            xd.ConditionFunctionsLessThanZero = cf;
            xd.LowerBoundOfX = -1.0;
            xd.LowerBoundOfY = -1.0;
            xd.UpperBoundOfX = 1.0;
            xd.UpperBoundOfY = 1.0;

            V.Function.ToLastType<double, double, double> f
                = new V.Function.ToLastType<double, double, double>(func);
            V.LevelCurve ls = new V.LevelCurve(f, 0.5, xd);
            ls.FindCurve(0.01);

            for (int i = 0; i < ls.CurvePointX.Count; i++)
            {
                result += ls.CurvePointX[i].ToString() + "\t";
                result += ls.CurvePointY[i].ToString() + "\r\n";
            }
        }
        private double func(double x, double y)
        {
            return x * x + y * y;
        }
        private double[] Box(double x, double y)
        {
            double[] f = new double[4];
            f[0] = x - 1.0;
            f[1] = -x - 1.0;
            f[2] = y - 1.0;
            f[3] = -y - 1.0;
            return f;
        }
    }
}
/*
-0.7	-0.1
-0.701347517730496	-0.09
-0.702553191489362	-0.08
-0.703617021276596	-0.07
-0.704539007092199	-0.0599999999999999
-0.70531914893617	-0.0499999999999999
-0.705957446808511	-0.04
-0.70645390070922	-0.03
-0.706808510638298	-0.02
-0.707021276595745	-0.01
-0.70709219858156	0
-0.707021276595745	0.01
-0.706808510638298	0.02
-0.70645390070922	0.03
-0.705957446808511	0.04
-0.70531914893617	0.05
-0.704539007092199	0.0600000000000001
-0.703617021276596	0.0700000000000001
-0.702553191489362	0.0800000000000001
-0.701347517730496	0.0900000000000001
-0.7	0.1
-0.691007194244604	-0.15
-0.693093525179856	-0.14
-0.695035971223022	-0.13
-0.696834532374101	-0.12
-0.698489208633094	-0.11
-0.7	-0.1
-0.7	0.1
-0.698489208633093	0.11
-0.696834532374101	0.12
-0.695035971223022	0.13
-0.693093525179856	0.14
-0.691007194244604	0.15
-0.681094890510949	-0.19
-0.683795620437956	-0.18
-0.686350364963504	-0.17
-0.688759124087591	-0.16
-0.69	-0.154516129032258
-0.69	0.154516129032258
-0.688759124087591	0.16
-0.686350364963504	0.17
-0.683795620437956	0.18
-0.681094890510949	0.19
-0.672	-0.22
-0.675185185185185	-0.21
-0.678222222222222	-0.2
-0.68	-0.193846153846154
-0.68	0.193846153846154
-0.678222222222222	0.2
-0.675185185185185	0.21
-0.672	0.22
-0.661428571428571	-0.25
-0.665112781954887	-0.24
-0.668646616541353	-0.23
-0.67	-0.226
-0.67	0.226
-0.668646616541353	0.23
-0.665112781954887	0.24
-0.661428571428571	0.25
-0.653511450381679	-0.27
-0.657557251908397	-0.26
-0.66	-0.253725490196079
-0.66	0.253725490196079
-0.657557251908397	0.26
-0.653511450381679	0.27
-0.64031007751938	-0.3
-0.644883720930233	-0.29
-0.649302325581395	-0.28
-0.65	-0.278363636363637
-0.65	0.278363636363637
-0.649302325581395	0.28
-0.644883720930233	0.29
-0.64031007751938	0.3
-0.630551181102362	-0.32
-0.635511811023622	-0.31
-0.64	-0.300655737704918
-0.64	0.300655737704918
-0.635511811023622	0.31
-0.630551181102362	0.32
-0.62	-0.34
-0.62536	-0.33
-0.63	-0.321076923076923
-0.63	0.321076923076923
-0.62536	0.33
-0.614390243902439	-0.35
-0.62	-0.34
-0.62	-0.34
-0.62	-0.34
-0.62	0.34
-0.62	0.34
-0.614390243902439	0.35
-0.602561983471074	-0.37
-0.608595041322314	-0.36
-0.61	-0.357605633802817
-0.61	0.357605633802817
-0.608595041322314	0.36
-0.602561983471074	0.37
-0.596302521008403	-0.38
-0.6	-0.374133333333333
-0.6	0.374133333333333
-0.596302521008403	0.38
-0.583076923076923	-0.4
-0.58982905982906	-0.39
-0.59	-0.38974025974026
-0.59	0.38974025974026
-0.58982905982906	0.39
-0.583076923076923	0.4
-0.576086956521739	-0.41
-0.58	-0.404444444444444
-0.58	0.404444444444444
-0.576086956521739	0.41
-0.561327433628319	-0.43
-0.568849557522124	-0.42
-0.57	-0.418433734939759
-0.57	0.418433734939759
-0.568849557522124	0.42
-0.561327433628319	0.43
-0.553513513513514	-0.44
-0.56	-0.431724137931034
-0.56	0.431724137931034
-0.553513513513514	0.44
-0.545412844036697	-0.45
-0.55	-0.44438202247191
-0.55	0.44438202247191
-0.545412844036697	0.45
-0.537009345794393	-0.46
-0.54	-0.456483516483516
-0.54	0.456483516483516
-0.537009345794393	0.46
-0.528285714285714	-0.47
-0.53	-0.468064516129032
-0.53	0.468064516129032
-0.528285714285714	0.47
-0.519223300970874	-0.48
-0.52	-0.479157894736842
-0.52	0.479157894736842
-0.519223300970874	0.48
-0.5	-0.5
-0.50980198019802	-0.49
-0.51	-0.48979381443299
-0.51	0.48979381443299
-0.50980198019802	0.49
-0.5	0.5
-0.5	-0.5
-0.5	-0.5
-0.5	-0.5
-0.5	0.5
-0.5	0.5
-0.5	0.5
-0.48979381443299	-0.51
-0.49	-0.50980198019802
-0.49	0.50980198019802
-0.48979381443299	0.51
-0.479157894736842	-0.52
-0.48	-0.519223300970874
-0.48	0.519223300970874
-0.479157894736842	0.52
-0.468064516129032	-0.53
-0.47	-0.528285714285714
-0.47	0.528285714285714
-0.468064516129032	0.53
-0.456483516483516	-0.54
-0.46	-0.537009345794393
-0.46	0.537009345794393
-0.456483516483516	0.54
-0.44438202247191	-0.55
-0.45	-0.545412844036697
-0.45	0.545412844036697
-0.44438202247191	0.55
-0.431724137931034	-0.56
-0.44	-0.553513513513514
-0.44	0.553513513513514
-0.431724137931034	0.56
-0.43	-0.561327433628319
-0.43	0.561327433628319
-0.418433734939759	-0.57
-0.42	-0.568849557522124
-0.42	0.568849557522124
-0.418433734939759	0.57
-0.404444444444444	-0.58
-0.41	-0.576086956521739
-0.41	0.576086956521739
-0.404444444444444	0.58
-0.4	-0.583076923076923
-0.4	0.583076923076923
-0.38974025974026	-0.59
-0.39	-0.58982905982906
-0.39	0.58982905982906
-0.38974025974026	0.59
-0.374133333333333	-0.6
-0.38	-0.596302521008403
-0.38	0.596302521008403
-0.374133333333333	0.6
-0.37	-0.602561983471074
-0.37	0.602561983471074
-0.357605633802817	-0.61
-0.36	-0.608595041322314
-0.36	0.608595041322314
-0.357605633802817	0.61
-0.34	-0.62
-0.35	-0.614390243902439
-0.35	0.614390243902439
-0.34	-0.62
-0.34	-0.62
-0.34	-0.62
-0.34	0.62
-0.34	0.62
-0.321076923076923	-0.63
-0.33	-0.62536
-0.33	0.62536
-0.321076923076923	0.63
-0.32	-0.630551181102362
-0.32	0.630551181102362
-0.300655737704918	-0.64
-0.31	-0.635511811023622
-0.31	0.635511811023622
-0.300655737704918	0.64
-0.3	-0.64031007751938
-0.3	0.64031007751938
-0.29	-0.644883720930233
-0.29	0.644883720930233
-0.278363636363637	-0.65
-0.28	-0.649302325581395
-0.28	0.649302325581395
-0.278363636363636	0.65
-0.27	-0.653511450381679
-0.27	0.653511450381679
-0.253725490196079	-0.66
-0.26	-0.657557251908397
-0.26	0.657557251908397
-0.253725490196078	0.66
-0.25	-0.661428571428571
-0.25	0.661428571428571
-0.24	-0.665112781954887
-0.24	0.665112781954887
-0.226	-0.67
-0.23	-0.668646616541353
-0.23	0.668646616541353
-0.226	0.67
-0.22	-0.672
-0.22	0.672
-0.21	-0.675185185185185
-0.21	0.675185185185185
-0.193846153846154	-0.68
-0.2	-0.678222222222222
-0.2	0.678222222222222
-0.193846153846154	0.68
-0.19	-0.681094890510949
-0.19	0.681094890510949
-0.18	-0.683795620437956
-0.18	0.683795620437956
-0.17	-0.686350364963504
-0.17	0.686350364963504
-0.154516129032258	-0.69
-0.16	-0.688759124087591
-0.16	0.688759124087591
-0.154516129032258	0.69
-0.15	-0.691007194244604
-0.15	0.691007194244604
-0.14	-0.693093525179856
-0.14	0.693093525179856
-0.13	-0.695035971223022
-0.13	0.695035971223022
-0.12	-0.696834532374101
-0.12	0.696834532374101
-0.1	-0.7
-0.11	-0.698489208633094
-0.11	0.698489208633094
-0.1	0.7
-0.1	-0.7
-0.1	0.7
-0.09	-0.701347517730496
-0.09	0.701347517730496
-0.08	-0.702553191489362
-0.08	0.702553191489362
-0.07	-0.703617021276596
-0.07	0.703617021276596
-0.0599999999999999	-0.704539007092199
-0.0599999999999999	0.704539007092199
-0.0499999999999999	-0.70531914893617
-0.0499999999999999	0.70531914893617
-0.04	-0.705957446808511
-0.04	0.705957446808511
-0.03	-0.70645390070922
-0.03	0.70645390070922
-0.02	-0.706808510638298
-0.02	0.706808510638298
-0.01	-0.707021276595745
-0.01	0.707021276595745
0	-0.70709219858156
0	0.70709219858156
0.01	-0.707021276595745
0.01	0.707021276595745
0.02	-0.706808510638298
0.02	0.706808510638298
0.03	-0.70645390070922
0.03	0.70645390070922
0.04	-0.705957446808511
0.04	0.705957446808511
0.05	-0.70531914893617
0.05	0.70531914893617
0.0600000000000001	-0.704539007092199
0.0600000000000001	0.704539007092199
0.0700000000000001	-0.703617021276596
0.0700000000000001	0.703617021276596
0.0800000000000001	-0.702553191489362
0.0800000000000001	0.702553191489362
0.0900000000000001	-0.701347517730496
0.0900000000000001	0.701347517730496
0.1	-0.7
0.1	-0.7
0.1	0.7
0.1	0.7
0.11	-0.698489208633093
0.11	0.698489208633093
0.12	-0.696834532374101
0.12	0.696834532374101
0.13	-0.695035971223022
0.13	0.695035971223022
0.14	-0.693093525179856
0.14	0.693093525179856
0.15	-0.691007194244604
0.154516129032258	-0.69
0.154516129032258	0.69
0.15	0.691007194244604
0.16	-0.688759124087591
0.16	0.688759124087591
0.17	-0.686350364963504
0.17	0.686350364963504
0.18	-0.683795620437956
0.18	0.683795620437956
0.19	-0.681094890510949
0.193846153846154	-0.68
0.193846153846154	0.68
0.19	0.681094890510949
0.2	-0.678222222222222
0.2	0.678222222222222
0.21	-0.675185185185185
0.21	0.675185185185185
0.22	-0.672
0.226	-0.67
0.226	0.67
0.22	0.672
0.23	-0.668646616541353
0.23	0.668646616541353
0.24	-0.665112781954887
0.24	0.665112781954887
0.25	-0.661428571428571
0.253725490196079	-0.66
0.253725490196078	0.66
0.25	0.661428571428571
0.26	-0.657557251908397
0.26	0.657557251908397
0.27	-0.653511450381679
0.278363636363637	-0.65
0.278363636363636	0.65
0.27	0.653511450381679
0.28	-0.649302325581395
0.28	0.649302325581395
0.29	-0.644883720930233
0.29	0.644883720930233
0.3	-0.64031007751938
0.300655737704918	-0.64
0.300655737704918	0.64
0.3	0.64031007751938
0.31	-0.635511811023622
0.31	0.635511811023622
0.32	-0.630551181102362
0.321076923076923	-0.63
0.321076923076923	0.63
0.32	0.630551181102362
0.33	-0.62536
0.34	-0.62
0.34	0.62
0.33	0.62536
0.34	-0.62
0.34	0.62
0.35	-0.614390243902439
0.357605633802817	-0.61
0.357605633802817	0.61
0.35	0.614390243902439
0.36	-0.608595041322314
0.36	0.608595041322314
0.37	-0.602561983471074
0.374133333333333	-0.6
0.374133333333333	0.6
0.37	0.602561983471074
0.38	-0.596302521008403
0.38974025974026	-0.59
0.38974025974026	0.59
0.38	0.596302521008403
0.39	-0.58982905982906
0.39	0.58982905982906
0.4	-0.583076923076923
0.404444444444444	-0.58
0.404444444444444	0.58
0.4	0.583076923076923
0.41	-0.576086956521739
0.418433734939759	-0.57
0.418433734939759	0.57
0.41	0.576086956521739
0.42	-0.568849557522124
0.42	0.568849557522124
0.43	-0.561327433628319
0.431724137931034	-0.56
0.431724137931034	0.56
0.43	0.561327433628319
0.44	-0.553513513513514
0.44438202247191	-0.55
0.44438202247191	0.55
0.44	0.553513513513514
0.45	-0.545412844036697
0.456483516483516	-0.54
0.456483516483516	0.54
0.45	0.545412844036697
0.46	-0.537009345794393
0.468064516129032	-0.53
0.468064516129032	0.53
0.46	0.537009345794393
0.47	-0.528285714285714
0.479157894736842	-0.52
0.479157894736842	0.52
0.47	0.528285714285714
0.48	-0.519223300970874
0.48979381443299	-0.51
0.48979381443299	0.51
0.48	0.519223300970874
0.49	-0.50980198019802
0.5	-0.5
0.5	0.5
0.49	0.50980198019802
0.5	-0.5
0.5	-0.5
0.5	-0.5
0.50980198019802	-0.49
0.50980198019802	0.49
0.5	0.5
0.5	0.5
0.5	0.5
0.51	-0.48979381443299
0.519223300970874	-0.48
0.519223300970874	0.48
0.51	0.48979381443299
0.52	-0.479157894736842
0.528285714285714	-0.47
0.528285714285714	0.47
0.52	0.479157894736842
0.53	-0.468064516129032
0.537009345794393	-0.46
0.537009345794393	0.46
0.53	0.468064516129032
0.54	-0.456483516483516
0.545412844036697	-0.45
0.545412844036697	0.45
0.54	0.456483516483516
0.55	-0.44438202247191
0.553513513513514	-0.44
0.553513513513514	0.44
0.55	0.44438202247191
0.56	-0.431724137931034
0.561327433628319	-0.43
0.568849557522124	-0.42
0.568849557522124	0.42
0.561327433628319	0.43
0.56	0.431724137931034
0.57	-0.418433734939759
0.576086956521739	-0.41
0.576086956521739	0.41
0.57	0.418433734939759
0.58	-0.404444444444444
0.583076923076923	-0.4
0.58982905982906	-0.39
0.58982905982906	0.39
0.583076923076923	0.4
0.58	0.404444444444444
0.59	-0.38974025974026
0.596302521008403	-0.38
0.596302521008403	0.38
0.59	0.38974025974026
0.6	-0.374133333333333
0.602561983471074	-0.37
0.608595041322314	-0.36
0.608595041322314	0.36
0.602561983471074	0.37
0.6	0.374133333333333
0.61	-0.357605633802817
0.614390243902439	-0.35
0.62	-0.34
0.62	0.34
0.614390243902439	0.35
0.61	0.357605633802817
0.62	-0.34
0.62536	-0.33
0.62536	0.33
0.62	0.34
0.63	-0.321076923076923
0.630551181102362	-0.32
0.635511811023622	-0.31
0.635511811023622	0.31
0.630551181102362	0.32
0.63	0.321076923076923
0.64	-0.300655737704918
0.64031007751938	-0.3
0.644883720930233	-0.29
0.649302325581395	-0.28
0.649302325581395	0.28
0.644883720930233	0.29
0.64031007751938	0.3
0.64	0.300655737704918
0.65	-0.278363636363636
0.653511450381679	-0.27
0.657557251908397	-0.26
0.657557251908397	0.26
0.653511450381679	0.27
0.65	0.278363636363636
0.66	-0.253725490196078
0.661428571428571	-0.25
0.665112781954887	-0.24
0.668646616541353	-0.23
0.668646616541353	0.23
0.665112781954887	0.24
0.661428571428571	0.25
0.66	0.253725490196078
0.67	-0.226
0.672	-0.22
0.675185185185185	-0.21
0.678222222222222	-0.2
0.678222222222222	0.2
0.675185185185185	0.21
0.672	0.22
0.67	0.226
0.68	-0.193846153846154
0.681094890510949	-0.19
0.683795620437956	-0.18
0.686350364963504	-0.17
0.688759124087591	-0.16
0.688759124087591	0.16
0.686350364963504	0.17
0.683795620437956	0.18
0.681094890510949	0.19
0.68	0.193846153846154
0.69	-0.154516129032258
0.691007194244604	-0.15
0.693093525179856	-0.14
0.695035971223022	-0.13
0.696834532374101	-0.12
0.698489208633094	-0.11
0.698489208633093	0.11
0.696834532374101	0.12
0.695035971223022	0.13
0.693093525179856	0.14
0.691007194244604	0.15
0.69	0.154516129032258
0.7	-0.1
0.7	-0.1
0.701347517730496	-0.09
0.702553191489362	-0.08
0.703617021276596	-0.07
0.704539007092199	-0.0599999999999999
0.70531914893617	-0.0499999999999999
0.705957446808511	-0.04
0.70645390070922	-0.03
0.706808510638298	-0.02
0.707021276595745	-0.01
0.70709219858156	0
0.707021276595745	0.01
0.706808510638298	0.02
0.70645390070922	0.03
0.705957446808511	0.04
0.70531914893617	0.05
0.704539007092199	0.0600000000000001
0.703617021276596	0.0700000000000001
0.702553191489362	0.0800000000000001
0.701347517730496	0.0900000000000001
0.7	0.1
0.7	0.1
*/